<?php


class dbaMsgCenter {

   function dbaMsgCenter(&$dba){
     $this->dba = &$dba;
   }

   function getall($ordered = false){
     if ($ordered){
       $orderStr = ' order by sender';
     }
     $check = $this->dba->query("select * from ".$this->dba->tableforwarder."_msgCenter$orderStr;");
     return $this->dba->fetch_rows_array();
   }

   function getByUid($uid,$ordered=false){
     if ($ordered){
       $orderStr = ' order by sender';
     }
     $this->dba->query("select * from ".$this->dba->tableforwarder."_msgCenter where owner='$uid'$orderStr;");
     return $this->dba->fetch_rows_array();
   }

   function num_msg($uid){
     $this->dba->query("select id from ".$this->dba->tableforwarder."_msgCenter where owner='$uid';");
     return $this->dba->num_rows();
   }

   function get($id){
     $check  = $this->dba->query("select * from ".$this->dba->tableforwarder."_msgCenter where id = $id;");
     return $this->dba->fetch_row_array();
   }

   function saveNumMsg($uid,$num=false){
     if (!$num){
       $num = $this->num_msg($uid);
     }
     return $this->dba->query("update ".$this->dba->tableforwarder."_User set num_msg='$num' where id = $uid;");
   }

   function loadNumMsg($uid){
     $sth = $this->dba->query("select num_msg from ".$this->dba->tableforwarder."_User where id = $uid;");
     $usr = $sth->fetch_row_Array();
     return $usr['num_msg'];
   }

   function del($id){
     return $this->dba->query("delete from ".$this->dba->tableforwarder."_msgCenter where id = $id;");
   }

   function send($uid,$sender,$subject,$body){
     return $this->dba->query("insert into ".$this->dba->tableforwarder."_msgCenter (owner,sender,time,subject,body) values ('$uid','$sender',".time().",'$subject','$body');");
   }
}
?>